package com.oa.ylms.apps.business.plan.impl;

import java.util.List;

import com.oa.ylms.apps.business.plan.ICheckPlanCategoryService;
import com.oa.ylms.apps.constants.IDEDStates;
import com.oa.ylms.apps.dao.plan.ICheckPlanCategoryDao;
import com.oa.ylms.apps.entity.plan.CheckPlanCategoryValue;

public class CheckPlanCategoryServiceImpl implements ICheckPlanCategoryService {
	private CheckPlanCategoryValue checkPlanCategory;
	private ICheckPlanCategoryDao categoryDao;

	@Override
	public int addCheckPlanCategory(String categoryName) throws Exception {
		checkPlanCategory.setCategoryName(categoryName);
		checkPlanCategory.setStates(IDEDStates.ENABLE);
		return categoryDao.addCheckPlanCategory(checkPlanCategory);
	}

	@Override
	public boolean deleteCheckPlanCategory(int categoryId) throws Exception {
		checkPlanCategory = queryByCategoryId(categoryId);
		if(checkPlanCategory != null){
			checkPlanCategory.setStates(IDEDStates.DELETE);
			return categoryDao.editCheckPlanCategory(checkPlanCategory);
		}
		return false;
	}

	@Override
	public boolean modifyCheckPlanCategory(int categoryId, String categoryName)
			throws Exception {
		checkPlanCategory = queryByCategoryId(categoryId);
		if(checkPlanCategory != null){
			checkPlanCategory.setCategoryName(categoryName);
			return categoryDao.editCheckPlanCategory(checkPlanCategory);
		}
		return false;
	}

	@Override
	public List<CheckPlanCategoryValue> queryAllCategoryInfo() throws Exception {
		return categoryDao.queryCheckPlanCategory(checkPlanCategory);
	}

	@Override
	public CheckPlanCategoryValue queryByCategoryId(int categoryId)
			throws Exception {
		checkPlanCategory.setCategoryId(categoryId);
		return categoryDao.queryByCategoryId(checkPlanCategory);
	}

	@Override
	public List<CheckPlanCategoryValue> queryCheckPlanCategory(Integer states)
			throws Exception {
		checkPlanCategory.setStates(states);
		return categoryDao.queryCheckPlanCategory(checkPlanCategory);
	}

	@Override
	public boolean toDisable(int categoryId) throws Exception {
		checkPlanCategory = queryByCategoryId(categoryId);
		if(checkPlanCategory != null){
			checkPlanCategory.setStates(IDEDStates.DISABLE);
			return categoryDao.editCheckPlanCategory(checkPlanCategory);
		}
		return false;
	}

	@Override
	public boolean toEnable(int categoryId) throws Exception {
		checkPlanCategory = queryByCategoryId(categoryId);
		if(checkPlanCategory != null){
			checkPlanCategory.setStates(IDEDStates.ENABLE);
			return categoryDao.editCheckPlanCategory(checkPlanCategory);
		}
		return false;
	}
	
	
	public CheckPlanCategoryValue getCheckPlanCategory() {
		return checkPlanCategory;
	}

	public void setCheckPlanCategory(CheckPlanCategoryValue checkPlanCategory) {
		this.checkPlanCategory = checkPlanCategory;
	}

	public ICheckPlanCategoryDao getCategoryDao() {
		return categoryDao;
	}

	public void setCategoryDao(ICheckPlanCategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

}
